﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _TypeId = "", organizeId = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 55.5);
            }, 200);
            e.stopPropagation();
        });

        //所属机构
        $("#OrganizeTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "所有",
            height: "250px",
            click: function (item) {
                organizeId = item.id;
                $('#btn_Search').trigger("click");
            }
        });
        $("#OrganizeTree").ComboBoxTreeSetValue(organizeId);
    }

    //种类树
    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../ResourceManage/RS_DeviceType/GetTreeJson",
            onnodeclick: function (item) {
                _TypeId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //设备列表
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = {
            TypeId: _TypeId,
            OrganizeId: organizeId,
            keyword: $("#txt_Keyword").val()
        }
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Device/GetPageListJson",
            datatype: "json",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                {
                    label: "所属机构", name: "OrganizeId", index: "OrganizeId", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return top.clientorganizeData[cellvalue] == null ? "" : top.clientorganizeData[cellvalue].FullName;
                    }
                },
                { label: "设备类别", name: "Type", index: "TypeName", width: 100, align: "left" },
                { label: "设备名称", name: "Name", index: "Name", width: 100, align: "left" },
                { label: "设备编号", name: "Code", index: "Code", width: 100, align: "left" },
                { label: "规格型号", name: "ModelNo", index: "ModelNo", width: 100, align: "left" },
                { label: "品牌", name: "Brand", index: "Brand", width: 100, align: "left" },
                {
                    label: "位置", name: "PStructId", index: "PStructId", width: 150, align: "left"
                },
                 {
                     label: "位置描述", name: "PSMemo", index: "PSMemo", width: 150, align: "left"
                 },
                 { label: "投用日期", name: "UseDate", index: "UseDate", width: 100, align: "left" },
                 {
                     label: "状态", name: "State", index: "State", width: 100, align: "center",
                     formatter: function (cellvalue, options, rowObject) {
                         switch (cellvalue) {
                             case 1: return "<span class='label label-primary'>正常运行</span>"; break;
                             case 2: return "<span class='label label-danger'>停用</span>"; break;
                             case 3: return "<span class='label label-danger'>报废</span>"; break;
                             case 4: return "<span class='label label-danger'>闲置</span>"; break;
                             default: return "<span class='label label-danger'>停用</span>"; break;
                         }
                     }
                 },
                { label: "附加说明", name: "Description", index: "Description", width: 200, align: "left" }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Code',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });

        //查询事件
        $("#btn_Search").click(function () {
            debugger;
            var a = [];
            //getck($("#itemTree").getCurrentNode(), a, function (item) { return item.id; });
            //_TypeId = a.join(",");
            var queryJson = {
                TypeId: _TypeId,
                OrganizeId: organizeId,
                keyword: $("#txt_Keyword").val()
            }
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }, page: 1
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    function getck(items, c, fn) {
        for (var i = 0, l = items.length; i < l; i++) {
            c.push(fn(items[i]));
            if (items[i].ChildNodes != null && items[i].ChildNodes.length > 0) {
                getck(items[i].ChildNodes, c, fn);
            }
        }
    }

    //配置设备种类
    function btn_addType() {
        top.tablist.newTab({
            id: "TypeForm",
            title: '设备种类',
            closed: true,
            icon: "fa fa-gavel",
            url: top.contentPath + '/ResourceManage/RS_DeviceType/Index'
        });
    };

    //新增
    function btn_add() {
        top.tablist.newTab({
            id: "Detail",
            title: "添加设备",
            closed: true,
            url: top.contentPath + "/ResourceManage/RS_Device/Detail"
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            top.tablist.newTab({
                id: "Detail_" + keyValue,
                title: "编辑设备",
                closed: true,
                url: top.contentPath + "/ResourceManage/RS_Device/Detail?keyValue=" + keyValue
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_Device/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    var queryJson = {
                        TypeId: _TypeId,
                        OrganizeId: organizeId,
                        keyword: $("#txt_Keyword").val()
                    }
                    $('#gridTable').jqGrid('setGridParam', {
                        postData: { queryJson: JSON.stringify(queryJson) }, page: 1
                    }).trigger('reloadGrid');
                }
            })
        }
    }

</script>


<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px;">设备种类</div>
            <div id="itemTree" style=" height: 320px; border-bottom: 1px dashed #cecece;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="OrganizeTree" type="selectTree" class="ui-select" style=" width: 200px;"></div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="lr-authorize" class="btn btn-default" onclick="btn_addType()"><i class="fa fa-gavel"></i>&nbsp;配置设备种类参数零配件</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

@*<div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>设备种类</h5>
                    </div>
                    <div class="ibox-content" style=" height: 45%;">
                        <div class="file-manager">
                            <h5>种类</h5>
                            <ul class="folder-list" id="DeviceType" style="padding: 0; overflow: auto"></ul>
                            <div class="hr-line-dashed"></div>
                            <button class="btn btn-primary btn-block" onclick="btn_addType()">新增设备种类</button>
                            <div class="hr-line-dashed"></div>
                        </div>
                    </div>
                    <div class="ibox-title">
                        <h5>房产列表</h5>
                    </div>
                    <div class="ibox-content" style=" height: 45%;">
                        <div class="file-manager">
                            <h5 class="tag-title">房产结构</h5>
                            <ul id="PStructs" style="padding: 0; height: 45%; overflow: auto"></ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-10 animated fadeInRight">
                <div class="row">
                    <div class="col-sm-12">

                        <div class="ibox">
                            <div class="ibox-title">
                                <span class="text-muted small pull-right">最后更新：<i class="fa fa-clock-o"></i><span id="ModifyDate"></span></span>
                                <h4>设备管理</h4>
                            </div>
                            <div class="ibox-content">
                                <div class="row m-b-sm m-t-sm">
                                    <div class="col-md-1">
                                        <button type="button" id="loading-example-btn" class="btn btn-white btn-sm" onclick="reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                    <div class="col-md-11">
                                        <div class="input-group">
                                            <input id="SearchKeyWord" type="text" placeholder="请输入设备名称或编号" class="input-sm form-control">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-sm btn-primary" onclick="btn_search()"> 搜索</button>
                                            </span>
                                            <span class="input-group-btn">
                                                <button type="button" class="btn btn-sm btn-success" onclick="btn_add()"><i class="fa fa-plus"></i> 新增</button>
                                            </span>
                                        </div>
                                    </div>
                                </div>
                                <div class="clients-list">
                                    <ul class="nav nav-tabs">
                                        <span class="pull-right small text-muted"><span id="Count"></span>个设备</span>
                                    </ul>
                                    <div class="tab-content">
                                        <div class="full-height-scroll">
                                            <div class="table-responsive">
                                                <table class=" footable  table table-striped table-hover" data-page-size="10">
                                                    <thead>
                                                        <tr>
                                                            <th>序号</th>
                                                            <th></th>
                                                            <th>编号</th>
                                                            <th>名称</th>
                                                            <th>状态</th>
                                                            <th data-hide="phone,tablet">规格型号</th>
                                                            <th data-hide="phone,tablet">出厂编号</th>
                                                            <th>操作</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody></tbody>
                                                    <tfoot>
                                                        <tr>
                                                            <td colspan="7">
                                                                <ul class="pagination pull-right"></ul>
                                                            </td>
                                                        </tr>
                                                    </tfoot>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <style>
        .folder-list li:hover {
            background-color: #eee;
        }

        .folder-list-selected {
            background-color: #eee;
        }
    </style>*@